# include <bits/stdc++.h>
# define INF 0x7fffffff
using namespace std;

inline char getc(){
    static char buf[1 << 18], *fs, *ft;
    return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}

inline int gn() {
    register int k = 0, f = 1;
    register char c = getc();
    for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
    for(; isdigit(c); c = getc()) k = k * 10 + c - '0';
    return k * f;
}

int main() { 
    freopen("in", "r", stdin);
    int h = gn(), m = gn(), ans = 0;
    for(int i = 0; i < 24; i++) {
        int tx = (h + i);
        int th = (h + i) % 24;
        int x = (th % 10) * 10 + th / 10;
        ans = (tx - h) * 60 + x - m;
        if(x < 60 && ans >= 0) break;
    }
    printf("%d\n", ans);
    return 0;
}
